package it.asvp.asvp_portal.data.entity.member;

import it.asvp.asvp_portal.data.entity.domain.BaseEntity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@SuppressWarnings("serial")
@Entity
@Table(name = "member_account", catalog = "asvp_db", uniqueConstraints = { @UniqueConstraint(columnNames = "id_member"),
    @UniqueConstraint(columnNames = "login") })
public class MemberAccount extends BaseEntity {

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "id_member", unique = true, nullable = false)
  private Member                 member;

  @Column(name = "login", unique = true, nullable = false, length = 50)
  private String                 login;

  @Column(name = "password", nullable = false, length = 50)
  private String                 password;

  @Temporal(TemporalType.DATE)
  @Column(name = "expire_date", nullable = false, length = 10)
  private Date                   expireDate;

  @OneToMany(fetch = FetchType.EAGER, mappedBy = "memberAccount")
  @Cascade({ CascadeType.ALL })
  private Set<MemberAccountRole> memberAccountRoles = new HashSet<MemberAccountRole>(0);

  public MemberAccount() {
  }

  public MemberAccount(Member member, String login, String password, Date lastUpdate, Date expireDate, Date createdOn) {
    this.member = member;
    this.login = login;
    this.password = password;
    this.lastUpdate = lastUpdate;
    this.expireDate = expireDate;
    this.createdOn = createdOn;
  }

  public Member getMember() {
    return this.member;
  }

  public void setMember(Member member) {
    this.member = member;
  }

  public String getLogin() {
    return this.login;
  }

  public void setLogin(String login) {
    this.login = login;
  }

  public String getPassword() {
    return this.password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public Date getExpireDate() {
    return expireDate;
  }

  public void setExpireDate(Date expireDate) {
    this.expireDate = expireDate;
  }

  public Set<MemberAccountRole> getMemberAccountRoles() {
    return this.memberAccountRoles;
  }

  public void setMemberAccountRoles(Set<MemberAccountRole> memberAccountRoles) {
    this.memberAccountRoles = memberAccountRoles;
  }
}
